﻿@{
    Bundle("jquery_validate");
}
           
@foreach(var i in Model.Addresses)
{
    <fieldset class="groupbox">
        <section>
            <script type="text/javascript">
                jQuery(document).ready(function () {
                    jQuery('@ID("#form_{0}", JDM.Int32(i.EntityID))').validate({
                        rules: {
                            city: {
                                required: true
                            },
                            address1: {
                                required: true
                            },
                            entityName: {
                                required: true
                            },
                            contactName: {
                                required: true
                            },
                            postalCode: {
                                required: true
                            },
                            email: {
                                required: true,
                                email: true
                            }
                        }
                    });
                    jQuery('@ID("#ddl_country_{0}", JDM.Int32(i.EntityID))').bind('change', function () {
                        jQuery.ajax({
                            type: 'post',
                            url: '@Url.Action(Loc.Act("List").Ctrl("Region").Area("Globalization"))',
                            dataType: 'json',
                            data: {
                                countryID: jQuery('@ID("#ddl_country_{0}", JDM.Int32(i.EntityID))').val()
                            },
                            success: function (rsp) {
                                var ddl = jQuery('@ID("#ddl_region_{0}", JDM.Int32(i.EntityID))');
                                ddl.empty();
                                jQuery.each(rsp, function (k, v) {
                                    ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                                });
                                ddl.val('@JDM.Int32(i.Region.EntityID)');
                            }
                        });
                    });
                    jQuery.ajax({
                        type: 'post',
                        url: '@Url.Action(Loc.Act("List").Ctrl("Country").Area("Globalization"))',
                        dataType: 'json',
                        success: function (rsp) {
                            var ddl = jQuery('@ID("#ddl_country_{0}", JDM.Int32(i.EntityID))');
                            ddl.empty();
                            jQuery.each(rsp, function (k, v) {
                                ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                            });
                            ddl.val('@JDM.Int32(i.Country.EntityID)');
                            ddl.change();
                        }
                    });
                });
            </script>
            <form id="@ID("form_{0}", JDM.Int32(i.EntityID))" action="@Url.Action(Loc.Act("UpdateAddress").Ctrl("Seller"))" method="post">
                <input type="hidden" name="id" value="@JDM.Int32(i.EntityID)" />
                <input type="hidden" name="sellerID" value="@JDM.Int32(Model.EntityID)" />
                <input type="hidden" name="flags" value="None" />
                <table>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Country"))</label>
                        </td>
                        <td>
                            <select id="@ID("ddl_country_{0}", JDM.Int32(i.EntityID))" name="countryID"></select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Region"))</label>
                        </td>
                        <td>
                            <select id="@ID("ddl_region_{0}", JDM.Int32(i.EntityID))" name="regionID"></select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("City"))</label>
                        </td>
                        <td>
                            <input type="text" name="city" value="@JDM.String(i.City)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Address1"))</label>
                        </td>
                        <td>
                            <input type="text" name="address1" value="@JDM.String(i.Address1)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Address2"))</label>
                        </td>
                        <td>
                            <input type="text" name="address2" value="@JDM.String(i.Address2)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("EntityName"))</label>
                        </td>
                        <td>
                            <input type="text" name="entityName" value="@JDM.String(i.EntityName)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("ContactName"))</label>
                        </td>
                        <td>
                            <input type="text" name="contactName" value="@JDM.String(i.ContactName)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("PostalCode"))</label>
                        </td>
                        <td>
                            <input type="text" name="postalCode" value="@JDM.String(i.PostalCode)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("PhoneNumber"))</label>
                        </td>
                        <td>
                            <input type="text" name="phoneNumber" value="@JDM.String(i.PhoneNumber)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("FaxNumber"))</label>
                        </td>
                        <td>
                            <input type="text" name="faxNumber" value="@JDM.String(i.FaxNumber)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.In("Common").Of("Vocab").Name("Email"))</label>
                        </td>
                        <td>
                            <input type="text" name="email" value="@JDM.String(i.Email)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.Name("Website"))</label>
                        </td>
                        <td>
                            <input type="text" name="website" value="@JDM.String(i.Website)" maxlength="100" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.In("API").Of("Enum").Of("SellerAddressFlags").Name("Active"))</label>
                        </td>
                        <td>
                            <input type="checkbox" name="flags" value="Active" @(JDM.HasFlags(i.Flags, "Active") ? "checked" : String.Empty) />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label>@T(Res.In("API").Of("Enum").Of("SellerAddressFlags").Name("Default"))</label>
                        </td>
                        <td>
                            <input type="checkbox" name="flags" value="Default" @(JDM.HasFlags(i.Flags, "Default") ? "checked" : String.Empty) />
                        </td>
                    </tr>
                </table>
                <ul class="bar toolbar">
                    <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
                    <li><a class="button confirm" href="@Url.Action(Loc.Act("DeleteAddress").Ctrl("Seller").Set(new
                    {
                        id = JDM.Int32(i.EntityID), 
                        sellerID = JDM.Int32(Model.EntityID)
                    }))">@T(Res.In("Common").Of("Act").Name("Delete"))</a></li>
                </ul>
            </form>
        </section>
    </fieldset>
}
<fieldset class="groupbox">
    <section>
        <script type="text/javascript">
            jQuery(document).ready(function () {
                jQuery('@ID("#form_new")').validate({
                    rules: {
                        city: {
                            required: true
                        },
                        address1: {
                            required: true
                        },
                        entityName: {
                            required: true
                        },
                        contactName: {
                            required: true
                        },
                        postalCode: {
                            required: true
                        },
                        email: {
                            required: true,
                            email: true
                        }
                    }
                });
                jQuery('@ID("#ddl_country_new")').bind('change', function () {
                    jQuery.ajax({
                        type: 'post',
                        url: '@Url.Action(Loc.Act("List").Ctrl("Region").Area("Globalization"))',
                        dataType: 'json',
                        data: {
                            countryID: jQuery('@ID("#ddl_country_new")').val()
                        },
                        success: function (rsp) {
                            var ddl = jQuery('@ID("#ddl_region_new")');
                            ddl.empty();
                            jQuery.each(rsp, function (k, v) {
                                ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                            });
                        }
                    });
                });
                jQuery.ajax({
                    type: 'post',
                    url: '@Url.Action(Loc.Act("List").Ctrl("Country").Area("Globalization"))',
                    dataType: 'json',
                    success: function (rsp) {
                        var ddl = jQuery('@ID("#ddl_country_new")');
                        ddl.empty();
                        jQuery.each(rsp, function (k, v) {
                            ddl.append('<option value=' + v.id + '>' + v.value + '</option>');
                        });
                        ddl.change();
                    }
                });
            });
        </script>
        <form id="@ID("form_new")" action="@Url.Action(Loc.Act("CreateAddress").Ctrl("Seller"))" method="post">
            <input type="hidden" name="sellerID" value="@JDM.Int32(Model.EntityID)" />
            <input type="hidden" name="flags" value="None" />
            <table>
                <tr>
                    <td>
                        <label>@T(Res.Name("Country"))</label>
                    </td>
                    <td>
                        <select id="@ID("ddl_country_new")" name="countryID"></select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Region"))</label>
                    </td>
                    <td>
                        <select id="@ID("ddl_region_new")" name="regionID"></select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("City"))</label>
                    </td>
                    <td>
                        <input type="text" name="city" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Address1"))</label>
                    </td>
                    <td>
                        <input type="text" name="address1" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Address2"))</label>
                    </td>
                    <td>
                        <input type="text" name="address2" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("EntityName"))</label>
                    </td>
                    <td>
                        <input type="text" name="entityName" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("ContactName"))</label>
                    </td>
                    <td>
                        <input type="text" name="contactName" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("PostalCode"))</label>
                    </td>
                    <td>
                        <input type="text" name="postalCode" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("PhoneNumber"))</label>
                    </td>
                    <td>
                        <input type="text" name="phoneNumber" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("FaxNumber"))</label>
                    </td>
                    <td>
                        <input type="text" name="faxNumber" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.In("Common").Of("Vocab").Name("Email"))</label>
                    </td>
                    <td>
                        <input type="text" name="email" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.Name("Website"))</label>
                    </td>
                    <td>
                        <input type="text" name="website" maxlength="100" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.In("API").Of("Enum").Of("SellerAddressFlags").Name("Active"))</label>
                    </td>
                    <td>
                        <input type="checkbox" name="flags" value="Active" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>@T(Res.In("API").Of("Enum").Of("SellerAddressFlags").Name("Default"))</label>
                    </td>
                    <td>
                        <input type="checkbox" name="flags" value="Default" />
                    </td>
                </tr>
            </table>
            <ul class="bar toolbar">
                <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
            </ul>
        </form>
    </section>
</fieldset>